﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Constant;

namespace Pixysoft.Weblications.Sango.Command.party
{
    partial class SangoPartyHandler
    {
        public party_close party_close()
        {
            string userCode = SangoManager.Authentication();

            party_close response = ReflectionManager.CreatePojo<party_close>();
            response.Succeed = false;

            Entities.Usr_Partymember member = PartyDao.tryGetActiveMember(userCode);

            if (member == null)
            {
                response.Message = "非军团成员";
                return response;
            }

            Entities.Usr_Party party = PartyDao.tryGetActiveParty(member.Partyprimarycode);

            if (!party.Initializeusercode.Equals(userCode, StringComparison.OrdinalIgnoreCase))
            {
                response.Message = "非军团创始人";
                return response;
            }

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

            PartyDao.closeParty(profile, party);

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;

            command.Begin(delegate()
            {
                command.Update(party);

                List<Entities.Usr_Partymember> members = PartyDao.getAllMembers(party.Primarycode);

                foreach (Entities.Usr_Partymember pmember in members)
                {
                    pmember.Memberstatus = GeneralStatusCollection.CLOSE;
                }

                command.Update(members.ToArray());

                command.Commit();
            });

            response.Succeed = true;
            return response;
        }


    }
    public interface party_close : ISangoResponse
    {
    }
}
